import request from '@/utils/request';
import { ProtocolItem } from './data';

export async function list(param?: any) {
    return request(`/AllLinks/workorder/_findpage`, {
        method: 'POST',
        data: param
    });
}
//下发
export async function sendOrder(param?: any) {
    return request(`/AllLinks/workorder/send_flux`, {
        method: 'POST',
        headers:{'Content-Type': 'application/json'},
        data: param
    });
}
//复制
export async function copyOrder(param?: any) {
    return request(`/AllLinks/workorder/batch_copy`, {
        method: 'POST',
        headers:{'Content-Type': 'application/json'},
        data: param
    });
}
//完成
export async function completeOrder(param?: any) {
    return request(`/AllLinks/workorder/batchComplete`, {
        method: 'POST',
        headers:{'Content-Type': 'application/json'},
        data: param
    });
}
//取消、完成
export async function updateState(param?: any) {
    return request(`/AllLinks/workorder/update_state/${param.id}/${param.state}`, {
        method: 'POST',
        param
    });
}

//设备查询下拉框列表
export async function instanceNopaging(params?: any) {
    return request(`/AllLinks/device-instance/_query/no-paging?paging=false`, {
        method: 'GET',
        params: params,
    });
}
//产品查询下拉框
export async function productNopaging(params?: any) {
    return request(`/AllLinks/device-instance/product/_query/no-paging?paging=false`, {
        method: 'GET',
        params: params,
    });
}
//获取图片列表
export async function getImg(params?: any) {
    return request(`/AllLinks/indeximage/find_by_type/1`, {
        method: 'GET',
        params: params,
    });
}
//获取指定设备上一次创建的工单信息
export async function getLast(params?: any) {
    return request(`/AllLinks/workorder/get_last/${params}`, {
        method: 'GET',
    });
}
//新建并下发
export async function saveSend(data: any) {
    return request(`/AllLinks/workorder/create_send`, {
        method: 'POST',
        data
    });
}
//新建
export async function save(data: any) {
    return request(`/AllLinks/workorder/_create`, {
        method: 'POST',
        data
    });
}
//编辑
export async function update(data: any) {
    return request(`/AllLinks/workorder/_update`, {
        method: 'POST',
        data
    });
}

export async function info(id: string) {
    return request(`/AllLinks/protocol/${id}`, {
        method: 'GET',
    });
}


export async function remove(id: string) {
    return request(`/AllLinks/protocol/${id}`, {
        method: 'DELETE',
    });
}

export async function changeDeploy(payload: any) {
    return request(`/AllLinks/protocol/${payload.id}/${payload.type}`, {
        method: 'POST',
    })
}

export async function convert(data: any) {
    return request(`/AllLinks/protocol/convert`, {
        method: 'POST',
        data
    });
}

export async function optionCode(type: 'decode' | 'encode', data: any) {
    return request(`/AllLinks/protocol/${type}`, {
        method: 'POST',
        data
    });
}

export async function providers() {
    return request(`/AllLinks/protocol/providers`, {
        method: 'GET'
    })
}

// 物模型单位
export async function getUnitsList(params?: any) {
    return request(`/AllLinks/protocol/units`, {
        method: 'GET',
        params: params,
    });
}